/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CadEmpresa.java
 *
 * Created on 01/09/2011, 16:24:08
 */
package visao;

import empresa.Empresa;
import endereco.Endereco;
import fachada.FachadaBDR;
import java.awt.Color;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JFormattedTextField;
import javax.swing.JOptionPane;
import util.CamposObrigatoriosException;
import util.ErroAcessoRepositorioException;
import util.KeyValue;
import util.Util;

/**
 *
 * @author Administrador
 */
public class CadEmpresa extends javax.swing.JFrame {

    public CadEmpresa() {
        initComponents();

        this.setLocationRelativeTo(null);
        this.setIconImage(new ImageIcon(getClass().getResource("/Imagens/empresa.gif")).getImage());
    }

    /** Creates new form CadEmpresa */
    public CadEmpresa(int idEmpresa) {
        initComponents();
        this.setLocationRelativeTo(null);
        this.setIconImage(new ImageIcon(getClass().getResource("/Imagens/empresa.gif")).getImage());

        try {
            // recuperando a instancia da fachada
            FachadaBDR objfaFachadaBDR = FachadaBDR.getInstancia();
            // recuperando o cargo 
            Empresa empresa = objfaFachadaBDR.procurarEmpresa(idEmpresa);
            Endereco endereco = empresa.getEndereco();

            jTextField_idEmpresa.setText(String.valueOf(empresa.getIdEmpresa()));
            jTextField_id_endereco.setText(String.valueOf(endereco.getIdEndereco()));
            jTextField_Rua.setText(endereco.getRua());
            jTextField_Numero.setText(endereco.getNumero());
            jTextField_Bairro.setText(endereco.getBairro());
            jTextField_Cidade.setText(endereco.getCidade());
            jComboBox_Uf.setSelectedItem(endereco.getUf());
            jComboBox_Pais.setSelectedItem(endereco.getPais());
            jTextField_Cep.setText(endereco.getCep());
            jTextArea_Especificacao.setText(empresa.getDescricaoEmpresa());
            jTextField_NomeFantasia.setText(empresa.getNomeFantasia());
            jCheckBox_Status.setSelected(empresa.getStatusEmpresa());
            jTextField_Cnpj.setText(empresa.getCnpj());
            jTextField_RazaoSocial.setText(empresa.getRasaoSocial());
            jTextField_Telefone.setText(empresa.getFone());


        } catch (ErroAcessoRepositorioException ex) {
            System.out.println(ex.getMessage());
        }

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jProgressBar1 = new javax.swing.JProgressBar();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jLabel_Codigo = new javax.swing.JLabel();
        jLabel_Nome = new javax.swing.JLabel();
        jTextField_NomeFantasia = new javax.swing.JTextField();
        jLabel_CNPJ = new javax.swing.JLabel();
        jLabel_RazaoSocial = new javax.swing.JLabel();
        jTextField_RazaoSocial = new javax.swing.JTextField();
        jCheckBox_Status = new javax.swing.JCheckBox();
        jTextField_Cnpj = new javax.swing.JTextField();
        jTextField_idEmpresa = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        jLabel_Especificacao = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea_Especificacao = new javax.swing.JTextArea();
        jPanel3 = new javax.swing.JPanel();
        jLabel_Rua = new javax.swing.JLabel();
        jLabel_Bairro = new javax.swing.JLabel();
        jLabel_Cidade = new javax.swing.JLabel();
        jLabel_Uf = new javax.swing.JLabel();
        jLabel_Pais = new javax.swing.JLabel();
        jLabel_Numero = new javax.swing.JLabel();
        jLabel_Cep = new javax.swing.JLabel();
        jTextField_Rua = new javax.swing.JTextField();
        jTextField_Numero = new javax.swing.JTextField();
        jTextField_Bairro = new javax.swing.JTextField();
        jTextField_Cidade = new javax.swing.JTextField();
        jComboBox_Uf = new javax.swing.JComboBox();
        jComboBox_Pais = new javax.swing.JComboBox();
        jTextField_Telefone = new javax.swing.JTextField();
        jLabel_Fone = new javax.swing.JLabel();
        jTextField_Cep = new javax.swing.JTextField();
        jTextField_id_endereco = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jButton_Cancelar = new javax.swing.JButton();
        jLabel_Mensagem = new javax.swing.JLabel();

        setTitle("Empresa");
        setResizable(false);

        jLabel_Codigo.setText("Codigo :");

        jLabel_Nome.setText("Nome :");

        jLabel_CNPJ.setText("CNPJ :");

        jLabel_RazaoSocial.setText("Razão Social :");

        jCheckBox_Status.setSelected(true);
        jCheckBox_Status.setText("Ativo");
        jCheckBox_Status.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox_StatusActionPerformed(evt);
            }
        });

        jTextField_Cnpj = new JFormattedTextField(Util.setMascara("##.###.###/####-##"));

        jTextField_idEmpresa.setText("0");
        jTextField_idEmpresa.setEnabled(false);
        jTextField_idEmpresa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField_idEmpresaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(37, 37, 37)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel_CNPJ, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel_Nome, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel_Codigo, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jTextField_NomeFantasia, javax.swing.GroupLayout.PREFERRED_SIZE, 417, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addComponent(jTextField_idEmpresa, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jCheckBox_Status)
                                .addGap(86, 86, 86))
                            .addComponent(jTextField_Cnpj, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel_RazaoSocial)
                        .addGap(18, 18, 18)
                        .addComponent(jTextField_RazaoSocial, javax.swing.GroupLayout.PREFERRED_SIZE, 408, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(29, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel_Codigo)
                        .addComponent(jTextField_idEmpresa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jCheckBox_Status))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel_Nome)
                    .addComponent(jTextField_NomeFantasia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel_CNPJ)
                    .addComponent(jTextField_Cnpj, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel_RazaoSocial)
                    .addComponent(jTextField_RazaoSocial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(71, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Empresa", jPanel1);

        jLabel_Especificacao.setText("Especificação");

        jTextArea_Especificacao.setColumns(20);
        jTextArea_Especificacao.setRows(5);
        jScrollPane1.setViewportView(jTextArea_Especificacao);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 521, Short.MAX_VALUE)
                    .addComponent(jLabel_Especificacao))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addComponent(jLabel_Especificacao)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 172, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Especificação", jPanel2);

        jLabel_Rua.setText("Rua :");

        jLabel_Bairro.setText("Bairro :");

        jLabel_Cidade.setText("Cidade :");

        jLabel_Uf.setText("UF :");

        jLabel_Pais.setText("País :");

        jLabel_Numero.setText("Numero :");

        jLabel_Cep.setText("CEP :");

        jComboBox_Uf.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "----", "AC", "AL", "AP", "AM", "BA", "CE", "DF", "ES", "GO", "MA", "MT", "MS", "MG", "PA", "PB", "PR", "PE", "PI", "RJ", "RN", "RS", "RO", "RR", "SC", "SP", "SE", "TO" }));

        jComboBox_Pais.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-----", "Brasil" }));

        jTextField_Telefone = new JFormattedTextField(Util.setMascara("(##)####-####"));

        jLabel_Fone.setText("Telafone :");

        jTextField_Cep = new JFormattedTextField(Util.setMascara("##.###-###"));

        jTextField_id_endereco.setText("0");
        jTextField_id_endereco.setVisible(false);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(26, 26, 26)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel_Rua, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel_Numero, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel_Bairro, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel_Cidade, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addComponent(jTextField_Cidade, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(69, 69, 69)
                                .addComponent(jLabel_Fone)
                                .addGap(18, 18, 18)
                                .addComponent(jTextField_Telefone, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jTextField_Rua, javax.swing.GroupLayout.PREFERRED_SIZE, 427, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel3Layout.createSequentialGroup()
                                    .addComponent(jTextField_Numero, javax.swing.GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE)
                                    .addGap(42, 42, 42)
                                    .addComponent(jLabel_Cep, javax.swing.GroupLayout.DEFAULT_SIZE, 71, Short.MAX_VALUE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jTextField_Cep, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(62, 62, 62)
                                    .addComponent(jTextField_id_endereco, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addComponent(jTextField_Bairro, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 416, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(106, 106, 106)
                        .addComponent(jLabel_Uf)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jComboBox_Uf, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(129, 129, 129)
                        .addComponent(jLabel_Pais)
                        .addGap(18, 18, 18)
                        .addComponent(jComboBox_Pais, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(26, 26, 26))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(15, 15, 15)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel_Rua)
                    .addComponent(jTextField_Rua, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel_Numero)
                    .addComponent(jTextField_Numero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jTextField_Cep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel_Cep)
                        .addComponent(jTextField_id_endereco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel_Bairro)
                    .addComponent(jTextField_Bairro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel_Cidade)
                    .addComponent(jTextField_Cidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel_Fone)
                        .addComponent(jTextField_Telefone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                        .addComponent(jLabel_Pais)
                        .addComponent(jComboBox_Pais, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                        .addComponent(jLabel_Uf, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jComboBox_Uf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(40, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Endereço", jPanel3);

        jButton1.setText("Ok");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton_Cancelar.setText("Calcelar");
        jButton_Cancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_CancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(28, 28, 28)
                .addComponent(jButton_Cancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 42, Short.MAX_VALUE)
                .addComponent(jLabel_Mensagem, javax.swing.GroupLayout.PREFERRED_SIZE, 272, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(24, 24, 24))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 546, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 255, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton1)
                            .addComponent(jButton_Cancelar))
                        .addContainerGap(22, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel_Mensagem, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jCheckBox_StatusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox_StatusActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jCheckBox_StatusActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:

        int idEmpresa = Integer.parseInt(jTextField_idEmpresa.getText());

        String NomeFantasia = jTextField_NomeFantasia.getText();
        Boolean statusEmpresa = jCheckBox_Status.isSelected();
        String cnpj = jTextField_Cnpj.getText();
        String rasaoSocial = jTextField_RazaoSocial.getText();
        String fone = jTextField_Telefone.getText();

        int idEndereco = Integer.parseInt(jTextField_id_endereco.getText());
        String rua = jTextField_Rua.getText();
        String numero = jTextField_Numero.getText();
        String bairro = jTextField_Bairro.getText();
        String cidade = jTextField_Cidade.getText();
        String uf = String.valueOf(jComboBox_Uf.getSelectedItem()).toString();
        String pais = String.valueOf(jComboBox_Pais.getSelectedItem()).toString();
        String cep = jTextField_Cep.getText();
        String especificacao = jTextArea_Especificacao.getText();
        try {
            FachadaBDR objFachadaBDR = FachadaBDR.getInstancia();

            Endereco endereco = new Endereco(idEndereco, rua, bairro, cidade, uf, cep, pais, numero);
            Empresa empresa = new Empresa(idEmpresa, endereco, cnpj, especificacao, rasaoSocial, NomeFantasia, fone, statusEmpresa, null);

            if (idEmpresa == 0) {
                objFachadaBDR.cadastrarEmpresa(empresa);
            } else // se não eu atualizo
            {
                objFachadaBDR.atualizarEmpresa(empresa);
            }

            String acao = (idEmpresa == 0) ? "Inserido" : "Atualizado";

            jLabel_Mensagem.setText("Empresa " + acao + " Com Sucesso!!!");
            jLabel_Mensagem.setForeground(Color.BLACK);

            if (idEmpresa == 0) {
                jTextField_id_endereco.setText("");
                jTextField_Rua.setText("");
                jTextField_Numero.setText("");
                jTextField_Bairro.setText("");
                jTextField_Cidade.setText("");
                jComboBox_Uf.setSelectedItem(0);
                jComboBox_Pais.setSelectedItem(0);
                jTextField_Cep.setText("");
                jTextArea_Especificacao.setText("");
                jTextField_NomeFantasia.setText("");
                jCheckBox_Status.setSelected(false);
                jTextField_Cnpj.setText("");
                jTextField_RazaoSocial.setText("");
                jTextField_Telefone.setText("");

            }

        } catch (CamposObrigatoriosException ex) {
            Logger.getLogger(CadEmpresa.class.getName()).log(Level.SEVERE, null, ex);
            jLabel_Mensagem.setText(ex.getMessage());
            jLabel_Mensagem.setForeground(Color.red);
        } catch (Exception ex) {
            Logger.getLogger(CadEmpresa.class.getName()).log(Level.SEVERE, null, ex);
            jLabel_Mensagem.setText(ex.getMessage());
            jLabel_Mensagem.setForeground(Color.red);
        }

    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton_CancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_CancelarActionPerformed
        // TODO add your handling code here:

        int cancelar = JOptionPane.showConfirmDialog(null, "Deseja cancelar ?");

        if (cancelar == JOptionPane.YES_OPTION) {

            dispose();

        } else {
        }

    }//GEN-LAST:event_jButton_CancelarActionPerformed

    private void jTextField_idEmpresaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField_idEmpresaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField_idEmpresaActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {

        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(CadEmpresa.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(CadEmpresa.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(CadEmpresa.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(CadEmpresa.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }




        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                try {
                    new CadEmpresa().setVisible(true);
                } catch (Exception ex) {
                    Logger.getLogger(CadCargo.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton_Cancelar;
    private javax.swing.JCheckBox jCheckBox_Status;
    private javax.swing.JComboBox jComboBox_Pais;
    private javax.swing.JComboBox jComboBox_Uf;
    private javax.swing.JLabel jLabel_Bairro;
    private javax.swing.JLabel jLabel_CNPJ;
    private javax.swing.JLabel jLabel_Cep;
    private javax.swing.JLabel jLabel_Cidade;
    private javax.swing.JLabel jLabel_Codigo;
    private javax.swing.JLabel jLabel_Especificacao;
    private javax.swing.JLabel jLabel_Fone;
    private javax.swing.JLabel jLabel_Mensagem;
    private javax.swing.JLabel jLabel_Nome;
    private javax.swing.JLabel jLabel_Numero;
    private javax.swing.JLabel jLabel_Pais;
    private javax.swing.JLabel jLabel_RazaoSocial;
    private javax.swing.JLabel jLabel_Rua;
    private javax.swing.JLabel jLabel_Uf;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JProgressBar jProgressBar1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextArea jTextArea_Especificacao;
    private javax.swing.JTextField jTextField_Bairro;
    private javax.swing.JTextField jTextField_Cep;
    private javax.swing.JTextField jTextField_Cidade;
    private javax.swing.JTextField jTextField_Cnpj;
    private javax.swing.JTextField jTextField_NomeFantasia;
    private javax.swing.JTextField jTextField_Numero;
    private javax.swing.JTextField jTextField_RazaoSocial;
    private javax.swing.JTextField jTextField_Rua;
    private javax.swing.JTextField jTextField_Telefone;
    private javax.swing.JTextField jTextField_idEmpresa;
    private javax.swing.JTextField jTextField_id_endereco;
    // End of variables declaration//GEN-END:variables
}
